package com.zlm.utils;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zlm
 * @date 2024/12/9
 */
public class BeanCopyUtils {

    private BeanCopyUtils() {}

    public static <T> T copyBean(Object source, Class<T> clazz){
        try {
            T target = clazz.newInstance();
            BeanUtils.copyProperties(source, target);
            return target;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
     public static <O,V> List<V> copyBeanList(List<O> list, Class<V> clazz){
         return list.stream().map(o -> {
             return copyBean(o, clazz);
         }).collect(Collectors.toList());
     }

}
